package com.netflexitysolutions.amazonws.s3.internal.operations;

import java.util.List;

import com.amazonaws.s3.doc._2006_03_01.SetObjectAccessControlPolicy;
import com.amazonaws.s3.doc._2006_03_01.SetObjectAccessControlPolicyResponse;
import com.netflexitysolutions.amazonws.s3.S3;
import com.netflexitysolutions.amazonws.s3.S3Grant;
import com.netflexitysolutions.amazonws.s3.S3ServerResponseStatus;
import com.netflexitysolutions.amazonws.s3.internal.utils.S3Utils;

public class SetObjectAccessControlPolicyOperation extends OperationExecutor<SetObjectAccessControlPolicy, S3ServerResponseStatus> {

    private String bucket;
    private String key;
    private List<S3Grant> acl;

    public SetObjectAccessControlPolicyOperation(S3 s3, String bucket, String key, List<S3Grant> acl) {
        super(s3);
        this.bucket = bucket;
        this.key = key;
        this.acl = acl;
    }

    @Override
    protected S3ServerResponseStatus call(SetObjectAccessControlPolicy request) {
        request.setBucket(bucket);
        request.setKey(key);
        request.setAccessControlList(S3Utils.convert(acl));
        injectCredentials(request, "SetObjectAccessControlPolicy", getS3().getAccessKey(), getS3().getSecretKey());
        SetObjectAccessControlPolicyResponse response = getS3().getService().setObjectAccessControlPolicy(request);
//TODO: make test to see what`s happen in real world
//Amazon S3 documentation mismatch: expected SetObjectAccessControlPolicyResponse with Status within
//received GetObjectAccessControlPolicyResponse?
        return new S3ServerResponseStatus(200, "OK");

    }

}
